package com.ruoyi.project.system.info.service.impl;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.PageQuery;
import com.ruoyi.framework.web.page.TableData;
import com.ruoyi.project.system.kind.domain.InfoKind;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.system.info.mapper.InfoMapper;
import com.ruoyi.project.system.info.domain.Info;
import com.ruoyi.project.system.info.service.IInfoService;
import com.ruoyi.common.utils.text.Convert;

/**
 * webService业务层处理
 * 
 * @author ruoyi
 * @date 2024-07-12
 */
@Service
public class InfoServiceImpl implements IInfoService 
{
    @Autowired
    private InfoMapper infoMapper;

    /**
     * 查询web
     * 
     * @param id web主键
     * @return web
     */
    @Override
    public Info selectInfoById(Long id)
    {
        return infoMapper.selectById(id);
    }

    /**
     * 查询web列表
     * 
     * @param info web
     * @return web
     */
    @Override
    public TableData<Info> selectInfoList(Info info, PageQuery pageQuery)
    {
        LambdaQueryWrapper<Info> lqw = new LambdaQueryWrapper<>();
        lqw.like(StringUtils.isNoneBlank(info.getInfoTitle()), Info::getInfoTitle,info.getInfoTitle());
        Page<Info> page = infoMapper.selectPage(pageQuery.build(), lqw);
        return TableData.build(page);
    }

    /**
     * 新增web
     * 
     * @param info web
     * @return 结果
     */
    @Override
    public int insertInfo(Info info)
    {
        info.setCreateTime(DateUtils.getNowDate());
        return infoMapper.insert(info);
    }

    /**
     * 修改web
     * 
     * @param info web
     * @return 结果
     */
    @Override
    public int updateInfo(Info info)
    {
        info.setUpdateTime(DateUtils.getNowDate());
        return infoMapper.updateById(info);
    }

    /**
     * 批量删除web
     * 
     * @param ids 需要删除的web主键
     * @return 结果
     */
    @Override
    public int deleteInfoByIds(String ids)
    {
        List<String> collect = Arrays.stream(ids.split(",")).collect(Collectors.toList());
        return infoMapper.deleteBatchIds(collect);
    }

    /**
     * 删除web信息
     * 
     * @param id web主键
     * @return 结果
     */
    @Override
    public int deleteInfoById(Long id)
    {
        return infoMapper.deleteById(id);
    }
}
